package com.potevio.simulator.strategy.impl;


import com.potevio.simulator.strategy.MsgFieldTypeStrategy;
import com.potevio.simulator.util.HexUtil;
import org.apache.commons.lang3.StringUtils;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @ClassName TimeCommand
 * @Description:
 * @Date 2021/6/1  10:27
 * @Author zyd
 */
public class TimeCommand implements MsgFieldTypeStrategy {

    private static final SimpleDateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-Mm-dd Hh:mm:ss");

    @Override
    public String encodeProcess(String msgFieldValue) throws Exception{
        if(StringUtils.isBlank(msgFieldValue)){
            msgFieldValue = SIMPLE_DATE_FORMAT.format(new Date());
        }
        msgFieldValue = HexUtil.time2Hex(msgFieldValue);
        return msgFieldValue;
    }

    @Override
    public String decodeProcess(String hexStr) throws Exception {
        return HexUtil.hex2Time(hexStr).toString();
    }
}
